package ctu.kfad.run;

import ctu.kfad.run.memory.ArraySizeDescriptor;

public class InstanceDescriptor {

    private final String className;
    private final ArraySizeDescriptor arrayDescriptor;

    private boolean live = true;
    private boolean shouldLive = false;
    private boolean inspected = false;

    private int referenceToMemory;

    public static InstanceDescriptor create(String className, int referenceToMemory) {
        return new InstanceDescriptor(className, null, referenceToMemory);
    }

    public static InstanceDescriptor create(ArraySizeDescriptor arrayDescriptor, int referenceToMemory) {
        return new InstanceDescriptor(null, arrayDescriptor, referenceToMemory);
    }

    private InstanceDescriptor(String className, ArraySizeDescriptor arrayDescriptor, int referenceToMemory) {
        this.className = className;
        this.arrayDescriptor = arrayDescriptor;
        if (className == null && arrayDescriptor.getName() == null)
            throw new RuntimeException("Instance needs to have name");
        this.referenceToMemory = referenceToMemory;
    }

    public String getClassName() {
        if (className == null) {
            return arrayDescriptor.getName();
        }
        return className;
    }

    public ArraySizeDescriptor getArrayDescriptor() {
        return arrayDescriptor;
    }

    public int getReferenceToMemory() {
        return referenceToMemory;
    }

    public void setReferenceToMemory(int referenceToMemory) {
        this.referenceToMemory = referenceToMemory;
    }

    public boolean isLive() {
        return live;
    }

    public void setLive(boolean live) {
        this.live = live;
    }

    public boolean isShouldLive() {
        return shouldLive;
    }

    public void setShouldLive(boolean shouldLive) {
        this.shouldLive = shouldLive;
    }

    public boolean isInspected() {
        return inspected;
    }

    public void setInspected(boolean inspected) {
        this.inspected = inspected;
    }
}
